package com.yiqi.lottery.feature.mine.view;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.suozhang.framework.entity.bo.UserInfoBo;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;
import com.suozhang.framework.utils.T;
import com.yiqi.lottery.R;
import com.yiqi.lottery.entity.bo.PayStautsBo;
import com.yiqi.lottery.entity.bo.RechargeBo;
import com.yiqi.lottery.feature.mine.contract.RechargeContract;
import com.yiqi.lottery.feature.mine.dependencies.recharge.DaggerRechargeComponent;
import com.yiqi.lottery.feature.mine.dependencies.recharge.RechargePresenterModule;

import javax.inject.Inject;

import static com.suozhang.framework.utils.AppUtil.fullScreen;

public class WithdrawActivity extends BaseActivity implements RechargeContract.View {


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.tv_withdraw_money)
    TextView mTvWithdrawMoney;
    @BindView(R.id.edt_value)
    EditText mEdtValue;

    private UserInfoBo mUserInfoBo;
    @Inject
    RechargeContract.Presenter mPresenter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_withdraw;
    }

    @Override
    protected void initInjector() {
        DaggerRechargeComponent.builder().rechargePresenterModule(new RechargePresenterModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        initToolBar(mToolbar, "提现", true, true);
    }

    @Override
    protected void initData() {
        mUserInfoBo = (UserInfoBo) this.getIntent().getSerializableExtra("user");

        if (mUserInfoBo != null) {
            mTvWithdrawMoney.setText("" + mUserInfoBo.getAvailable_amount());
        }

    }


    @Override
    protected void initSystemParams() {
//        super.initSystemParams();
        fullScreen(this);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }


    @OnClick(R.id.btn_withdraw_wx)
    public void onViewClicked() {
        if (!AM.user().isLogin()) return;
        if (mUserInfoBo == null) return;
        if (TextUtils.isEmpty(mEdtValue.getText().toString())) {
            T.showShort("请输入提现金额！");
            return;
        }
        double value = Double.valueOf(mEdtValue.getText().toString());
        if (value > mUserInfoBo.getAvailable_amount()) {
            T.showShort("金额超出可提现金额范围");
            return;
        }
        mPresenter.toWithdraw(value);
    }

    @Override
    public void showMyRechargeSuccess(RechargeBo msg) {

    }

    @Override
    public void showWithdrawSuccess(RechargeBo msg) {
        T.showShort("提现请求成功！");
        finish();
    }

    @Override
    public void showYLPaySuccess(PayStautsBo msg) {

    }

    @Override
    public void showUserInfoSuccess(UserInfoBo userInfoBo) {

    }

    @Override
    public void showMyRechargeError(String msg) {
        T.showShort("提现失败！" + msg);
    }

}
